package com.pll.controller;

import com.pll.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ws-test/merchant")
public class WebSocketTestController {

    @Autowired
    private ChatClient chatClient;

    /**
     * 模拟商家登录并建立WebSocket连接
     * @param merchantId 要模拟的商家ID
     * @return String
     */
    @GetMapping("/connect")
    public String connect(@RequestParam("merchantId") Long merchantId) {
        chatClient.connect(merchantId);
        return "商家 " + merchantId + " 正在尝试连接...";
    }

    /**
     * 模拟商家向用户发送消息
     * @param userId 目标用户ID
     * @param content 消息内容
     * @return String
     */
    @GetMapping("/send")
    public String sendMessage(@RequestParam("userId") Long userId, @RequestParam("content") String content) {
        chatClient.sendMessageToUser(userId, content);
        return "正在向用户 " + userId + " 发送消息: " + content;
    }
} 